﻿﻿define(function(require, exports, module){
	var App = window.App = new Nuui.Application({
		indexAnchor:Nuui.config.CONFIG_INDEX_AUCHOR,
        authAnchor:"login/login/index",
     //   authAnchor:null,
        authorizer:function() {
           if (!App.storage.get("isUserLoggedIn")) { //取用户是否登录
               return false;
           }
            return true;
        },
      //  authorizer:null
	});

	// APP LAYOUT DEFINITION
	// =====================

	App.addRegions({
		headerRegion:"#app-header",
		footerRegion:"#app-footer",
		container:"#app-container",
		navRegion:"#app-nav"
	});

	App.container.on("show", function(){
		window.scrollTo(0, 0);
	});

	App.header = new Nuui.Header();
    App.headerRegion.show(App.header);

	App.footer = new Nuui.Footer();
	App.footerRegion.show(App.footer);

	App.nav = new Nuui.Nav();
	App.navRegion.show(App.nav);

	// 用于点击input框,当前页面高度变化时(弹出键盘),input框滚回屏幕中央
	// 需要依赖css,input的父节点中不能有relative的
	$(window).on("resize", function(){
		var input = $("input:focus");
		if(input[0]){
			var container = App.container.$el;
			console.log(input[0].offsetTop);
			var destScrollTop = input[0].offsetTop + input.outerHeight(true) / 2 - container.outerHeight(true) / 2;
			container.animate({
				scrollTop:destScrollTop
			}, 100);
		}
	});

	App.start();
	App.history.start();

	// 只在web版时直接覆盖,hibrid情况需要讨论
	if(Nuui.os == "web"){
		document.addEventListener("backbutton", function(event){
			console.log("back");
			App.back();
			event.preventDefault();
		}, false);
	}

});